package com.customer.crm.customer.controller;

import com.customer.crm.customer.pojo.Customer;
import com.customer.crm.customer.service.CustomerService;
import com.customer.crm.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * The type Customer controller.
 *
 * @author Lyp
 * @create 2021 /12/22
 */
@Controller
public class CustomerController {

    /**
     * The Customer service.
     */
    @Autowired
    CustomerService customerService;

    /**
     * To customer string.
     *
     * @return the string
     */
    @RequestMapping(value = "/manage/customer/CustomerAction_list.action")
    public String toCustomer() {
        return "views/manage/customer/customer";
    }

    @RequestMapping(value = "/manage/customer/CustomerAction_toList.action")
    public String toCustomerList() {
        return "views/manage/customer/list";
    }


    /**
     * Page model map.
     * 分页查询
     *
     * @param page the page
     * @param rows the rows
     * @return the model map
     */
    @RequestMapping("/manage/customer/CustomerAction_pagination.action")
    @ResponseBody
    public ModelMap page(@RequestParam("page") Long page,
                         @RequestParam("rows") Long rows) {
        List<Customer> list = customerService.findCustomer(page - 1, rows);
        for (Customer c : list) {
            c.setDays(customerService.findDays());
        }
        ModelMap modelMap = new ModelMap();

        modelMap.put("totalRows", list.size());
        modelMap.put("result", list);

        ModelMap modelMap1 = new ModelMap();
        modelMap1.put("data", modelMap);
        return modelMap1;
    }

    /**
     * Photo result data.
     * 图片显示
     *
     * @param id the id
     * @return the result data
     */
    @RequestMapping("/manage/customer/CustomerAction_isfollowed.action")
    @ResponseBody
    public ResultData photo(@RequestParam("customerId") Integer id) {
        Customer customer = customerService.getById(id);
        ResultData resultData = ResultData.buildSuccessResult("成功", customer);
        return resultData;
    }

    /**
     * Follow model map.
     * 关注客户事件
     *
     * @return the model map
     */
    @RequestMapping("/manage/customer/CustomerAction_follow.action")
    @ResponseBody
    public ModelMap follow() {
        ModelMap modelMap = new ModelMap();
        modelMap.put("success", true);

        return modelMap;
    }

    /**
     * Unfollow model map.
     * 取消关注客户事件
     *
     * @return the model map
     */
    @RequestMapping("/manage/customer/CustomerAction_unfollow.action")
    @ResponseBody
    public ModelMap unfollow() {
        ModelMap modelMap = new ModelMap();
        modelMap.put("success", true);

        return modelMap;
    }

    /**
     * My customer model map.
     * 我的客户
     *
     * @return the model map
     */
    @RequestMapping("/manage/customer/CustomerAction_myCustomer.action")
    public ModelMap myCustomer() {
        ModelMap modelMap = new ModelMap();
        return modelMap;
    }

    @RequestMapping("/manage/customer/CustomerAction_showAdd.action")
    public String  addCustomer(){
        return  "views/manage/customer/add";

    }

}

